package com.aita.diamond.service

import com.gd.magic.Service
import com.gd.domain.party.Organization
import com.gd.domain.party.Operator
import com.aita.diamond.WeeklyReport
import com.aita.diamond.Advice
import com.aita.diamond.PublicInfo

class WeekReportService implements Service {
			
	public static final String FORMAT_YEARMONTH = "yyyyMM"
	
	def saveWeekReport(WeeklyReport report){
		assert report: X("周报信息为空")
		if(report.id == null)//新增
		{
			report.oper = loginService.currentOperator()
			report.acceptDate = new Date()
		}else
		{
			assert report.reportStatus == 1 : X("非新建状态不能修改")
		}
	 	report.reportStatus = 1
	 	
	 	logService.log(report.id == null ?101040:101045 ,(report.id == null ?"新增":"修改") +"周报信息(" + report.id +")")
		report.persistOrMerge()
	}
	
	def loadWeekReport(long id){
		WeeklyReport report = WeeklyReport.load(id)
		assert report : X("未找到"+ id)
		def result = [report:report]
		return result;
	}
	
	def commitReport(long id){
		logger.debug( "  id...............") 
		WeeklyReport report = WeeklyReport.load(id)
		
		assert report.reportStatus == 1  : X("非新建状态不能提交")
		report.reportStatus = 2 //提交
		
		logService.log(101041,"提交周报信息(" + report.id +")")
		report.persistOrMerge()
	}
	
	def readReport(WeeklyReport report){
		assert report: X("周报信息为空")
		assert report.reportStatus == 2  : X("非提交状态不能审阅")
		report.reportStatus = 3 //已阅
		
	 	logService.log(101042,"审阅周报信息(" + report.id +")")
		report.persistOrMerge()
	}
	
	
	def saveadvice(Advice advice,long operid)
	{
		assert advice: X("周报信息为空")
		
		Operator operTo = Operator.load(operid)
		assert operTo: X("接收人员为空")
		
		if(advice.id == null)//新增
		{
			advice.oper = loginService.currentOperator()
			advice.acceptDate = new Date()
		}else
		{
			assert advice.reportStatus == 1 : X("非新建状态不能修改")
		}
		advice.operTo = operTo
		advice.reportStatus = 1
		
		logService.log(advice.id == null ?101043:101046,(advice.id == null ?"新增":"修改") +"建议信箱信息(" + advice.id +")")
		advice.persistOrMerge()
	}
	
	
	def loadAdvice(long id){
		Advice advice = Advice.load(id)
		assert advice : X("未找到"+ id)
		def result = [advice:advice,oper:advice.operTo]
		return result;
	}
	
	
	
	def saveNews(PublicInfo publicInfo)
	{
		assert publicInfo: X("公告栏信息为空")
		
		if(publicInfo.id == null)//新增
		{
			publicInfo.oper = loginService.currentOperator()
			publicInfo.acceptDate = new Date()
		}else
		{
			assert publicInfo.reportStatus == 1 : X("非新建状态不能修改")
		}
		publicInfo.reportStatus = 1
		
		logService.log(publicInfo.id == null ?101044:101047,(publicInfo.id == null ?"新增":"修改") +"公告栏信息(" + publicInfo.id +")")
		publicInfo.persistOrMerge()
	}
	
	def loadNews(long id){
		PublicInfo publicInfo = PublicInfo.load(id)
		assert publicInfo : X("未找到"+ id)
		def result = [publicInfo:publicInfo]
		return result;
	}
}